package cn.adair.oxframe.base;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import butterknife.ButterKnife;
import cn.adair.oxframe.bean.Titlebean;

public abstract class OxBaseFragment extends Fragment implements OxBaseCallback {

    protected Context _mContext;
    protected FragmentActivity _mActivity;
    private Bundle iSavedInstanceState;

    /**
     * 视图是否加载完毕
     */
    private boolean isComplete = false;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(initLayout(), container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        _mContext = getContext();
        _mActivity = getActivity();
        iSavedInstanceState = savedInstanceState;
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public void onResume() {
        iStartload();
        super.onResume();
    }

    /**
     * 控制fragment 懒加载
     */
    private void iStartload() {
        if (!isComplete) {
            initData(iSavedInstanceState);
            isComplete = true;
        }
    }

    protected Titlebean mTitlebean;

    public void setTitlebean(Titlebean bean) {
        this.mTitlebean = bean;
    }

}
